package com.chujian.Adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chujian.model.FoodList;
import com.chujian.model.Order;
import com.chujian.orderingsystem.R;
/**
 * 当前订单明细的适配器
 * @author 周映凯
 *
 */
public class OrderCurrentDetailAdapter extends BaseAdapter{
	private LayoutInflater mLayoutInflater;
	private Context context;
	private TextView tvTotalPrce;
	private List<FoodList>mDataList;
	private Order mOrder;
	

	public OrderCurrentDetailAdapter(Context context, TextView tvTotalPrce,
			Order mOrder) {
		super();
		mLayoutInflater=LayoutInflater.from(context);
		this.context = context;
		this.tvTotalPrce = tvTotalPrce;
		this.mOrder = mOrder;
		mDataList=mOrder.getFoodList();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mDataList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mDataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder=null;
		if(convertView==null){
			holder=new ViewHolder();
			convertView=mLayoutInflater.inflate(R.layout.current_order_detail_item, null);
			holder.tvFoodName=(TextView) convertView.findViewById(R.id.tv_codi_food_name);
			holder.tvStatus=(TextView) convertView.findViewById(R.id.tv_codi_food_status);
			holder.tvPrice=(TextView) convertView.findViewById(R.id.tv_codi_food_price);
			holder.tvCount=(TextView) convertView.findViewById(R.id.tv_codi_food_count);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		// 设置奇偶行不同背景颜色
		if (position % 2 == 0) {
			convertView.setBackgroundColor(Color.parseColor("#dadada"));
		} else {
			convertView.setBackgroundColor(Color.parseColor("#ffffff"));
		}
		holder.tvFoodName.setText(mDataList.get(position).getFoodName());
		holder.tvStatus.setText(""+mDataList.get(position).getFoodStatus());
		holder.tvPrice.setText(""+mDataList.get(position).getFoodPrice());
		holder.tvCount.setText(mDataList.get(position).getFoodAmount()+"");
//		
		if(mDataList.get(position).getFoodStatus()==2){
			holder.tvFoodName.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
			holder.tvStatus.setText("成功退菜");
		}else if(mDataList.get(position).getFoodStatus()==1){
			holder.tvStatus.setText("发起退菜");
		}
		
		return convertView;
	}
	class ViewHolder{
		public TextView tvFoodName;
		public TextView tvStatus;
		public TextView tvPrice;
		public TextView tvCount;
	}
}
